# Makefile for Hysteria Rust

.PHONY: all build test clean install dev fmt lint docker

# Default target
all: build

# Build release version
build:
	@echo "Building Hysteria..."
	cargo build --release
	@echo "Building frontend..."
	cd web && npm install && npm run build

# Build debug version
build-debug:
	cargo build

# Run tests
test:
	cargo test --workspace

# Run tests with output
test-verbose:
	cargo test --workspace -- --nocapture

# Clean build artifacts
clean:
	cargo clean
	rm -rf web/dist web/node_modules

# Install to system
install: build
	@echo "Installing to /usr/local/bin..."
	sudo cp target/release/hysteria /usr/local/bin/
	sudo mkdir -p /etc/hysteria /var/lib/hysteria
	sudo cp config/*.example.yaml /etc/hysteria/

# Development mode
dev:
	cargo watch -x 'run --bin hysteria -- server -c config/server.yaml'

# Format code
fmt:
	cargo fmt --all
	cd web && npm run format

# Lint code
lint:
	cargo clippy --all-targets --all-features
	cd web && npm run lint

# Build Docker image
docker:
	docker build -t hysteria-rust:latest .

# Run with Docker Compose
docker-up:
	docker-compose up -d

# Stop Docker Compose
docker-down:
	docker-compose down

# View Docker logs
docker-logs:
	docker-compose logs -f

# Run benchmarks
bench:
	cargo bench

# Generate documentation
docs:
	cargo doc --no-deps --open

# Check for security vulnerabilities
audit:
	cargo audit

# Update dependencies
update:
	cargo update
	cd web && npm update

# Create release package
release: build
	@echo "Creating release package..."
	mkdir -p release/hysteria-rust-v2.0.0
	cp target/release/hysteria release/hysteria-rust-v2.0.0/
	cp -r web/dist release/hysteria-rust-v2.0.0/web
	cp -r config release/hysteria-rust-v2.0.0/
	cp README.md QUICK_START.md LICENSE release/hysteria-rust-v2.0.0/
	cd release && tar -czf hysteria-rust-v2.0.0-linux-amd64.tar.gz hysteria-rust-v2.0.0/
	@echo "Release package created: release/hysteria-rust-v2.0.0-linux-amd64.tar.gz"
